package com.example.ayniu.treadmill;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.ayniu.treadmill.base.BaseActivity;

public class NewMemberActivity extends BaseActivity {

    private TextView title_membertar,tv_cancel,tv_sure,tv_delete;
    private EditText et_name,et_phone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_member);

        Intent intent = getIntent();
        String fromeid = intent.getStringExtra("fromId");

        initView(fromeid);
    }

    //根据不同的来源，进行不同初始化（修改成员or添加成员）
    private void initView(String fromId){
        title_membertar = (TextView) findViewById(R.id.title_membertar);
        tv_cancel = (TextView) findViewById(R.id.tvmem_cancel);
        tv_sure = (TextView) findViewById(R.id.tvmem_sure);
        et_name = (EditText) findViewById(R.id.et_modifyname);
        et_phone = (EditText) findViewById(R.id.et_modifyphone);
        tv_delete = (TextView) findViewById(R.id.tv_delete);
        tv_delete.setVisibility(View.GONE);
        switch (fromId){
            //添加成员
            case "add":{
                title_membertar.setText("添加成员");
                tv_cancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        finish();
                    }
                });
                tv_sure.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(NewMemberActivity.this, "添加成功", Toast.LENGTH_LONG).show();
                        finish();
                    }
                });
            }
                break;
            //修改成员
            case "modify":{
                title_membertar.setText("修改成员");
                et_name.setText(getIntent().getStringExtra("member_name"));
                et_phone.setText(getIntent().getStringExtra("member_phone"));
                tv_delete.setVisibility(View.VISIBLE);
                tv_cancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        finish();
                    }
                });
                tv_sure.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(NewMemberActivity.this, "修改成功", Toast.LENGTH_LONG).show();
                        finish();
                    }
                });
            }
                break;
            default:
                break;
        }
    }
}
